import dom, { ajax } from "../init.js";
import { obj } from "../index.js";
import animate from "../../util/animate.js";
import * as content from "../content/article/aritcle.js";
import { initCreatedShuoshuo } from "../content/shuoshuo/shuoshuo.js";
import { initMyArticle } from "../content/myarticle/myaricle.js";
import { initAbout } from "../content/about/about.js";
import { initcomment } from "../content/comment/comment.js";
import { initandmi } from "../content/andmi/andmi.js";

export default {
  async ulclick(e: Event) {
    if (e.target === dom.index.index) {
      if ((e.target as HTMLElement).classList.length >= 2) return;
      obj.hashEle = e.target as HTMLElement;
      location.hash = "/index";
    }
    if (e.target === dom.index.comment) {
      if ((e.target as HTMLElement).classList.length >= 2) return;
      obj.hashEle = e.target as HTMLElement;
      location.hash = "/comment";
    }
    if (e.target === dom.index.shuoshuo) {
      if ((e.target as HTMLElement).classList.length >= 2) return;
      obj.hashEle = e.target as HTMLElement;
      location.hash = "/shuoshuo";
    }
    if (e.target === dom.index.article) {
      if ((e.target as HTMLElement).classList.length >= 2) return;
      obj.hashEle = e.target as HTMLElement;
      location.hash = "/MyArticle";
    }
    if (e.target === dom.index.about) {
      if ((e.target as HTMLElement).classList.length >= 2) return;
      obj.hashEle = e.target as HTMLElement;
      location.hash = "/About";
    }
    if (e.target === dom.index.andmi) {
      if ((e.target as HTMLElement).classList.length >= 2) return;
      obj.hashEle = e.target as HTMLElement;
      location.hash = "/Andmi";
    }
  },
};

export function classche(ele: HTMLElement) {
  dom.index.indexAll.forEach((item) => {
    item.classList.remove("indexlist");
  });
  ele.classList.add("indexlist");
}

export function toarticle() {
  classche(dom.index.article);
  initMyArticle();
}
export function initurl() {
  if (location.href.includes("#")) {
    location.href = location.href.slice(0, location.href.indexOf("#") + 1);
  }
}
